package com.woniu.product.controller;


import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.product.pojo.ServiceType;
import com.woniu.product.service.IServiceTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 服务类型表 前端控制器
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/service-type")
public class ServiceTypeController {
    @Autowired
    private IServiceTypeService serviceTypeService;

    // 添加服务类别
    @ApiOperation("添加服务类别")
    @PostMapping("/addServiceType")
    public Result<ServiceType> addServiceType(@RequestBody ServiceType serviceType){
        serviceTypeService.addServiceType(serviceType);
        return Result.ok();
    }

    // 删除服务类别
    @ApiOperation("删除服务类别")
    @DeleteMapping("/deleteServiceType/{id}")
    public Result<ServiceType> deleteServiceType(@PathVariable String id){
        serviceTypeService.deleteServiceType(id);
        return Result.ok();
    }

    // 修改服务类型
    @ApiOperation("修改服务类别")
    @PutMapping("/updateServiceType")
    public Result<ServiceType> updateServiceType(@RequestBody ServiceType serviceType){
        serviceTypeService.updateServiceType(serviceType);
        return Result.ok();
    }

    // 查询服务类型
    @ApiOperation("查询服务类型")
    @PostMapping("/queryServiceType/{currentPage}/{pageSize}")
    public Result<PageResult<ServiceType>> queryServiceType(@PathVariable Integer currentPage,
                                                @PathVariable Integer pageSize,
                                                String serviceTypeName){
        PageResult<ServiceType> pageResult = serviceTypeService.queryServiceType(currentPage,pageSize,serviceTypeName);
        return Result.ok(pageResult);
    }

}
